package com.tsingtao.springcloudproject1.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lihongyan
 */
@RestController
@RequestMapping("/sentinel")
public class TestSentinelController {

    @GetMapping("/test-sentinel-annotation")
    @SentinelResource(value = "testSentinelAnnotation", fallback = "fallbackTestSentinelAnnotation")
    public String testSentinelAnnotation() {
        return "hello, sentinel annotation";
    }

    public String fallbackTestSentinelAnnotation() {
        return "fallback......";
    }

    @GetMapping("/test-sentinel-fusing")
    @SentinelResource(value = "testSentinelFusing", fallback = "fallbackTestSentinelFusing")
    public String testSentinelFusing() {
        try {
            Thread.sleep(1000);
        } catch (Exception e ) {
            e.printStackTrace();
        }
        return "hell, sentinel fusing";
    }

    public String fallbackTestSentinelFusing() {
        return "fallback test sentinel fusing";
    }

}
